/**
 * 哈希
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function (ransomNote, magazine) {
    let ransomMap = new Map()
    for (let i = 0; i < ransomNote.length; i++) {
        ransomMap.set(ransomNote[i], (ransomMap.get(ransomNote[i]) || 0) + 1)
    }

    let mapValue
    for (let j = 0; j < magazine.length; j++) {
        mapValue = ransomMap.get(magazine[j])
        if (mapValue === undefined) continue
        ransomMap.set(magazine[j], mapValue - 1)
        if (mapValue - 1 === 0) {
            ransomMap.delete(magazine[j])
        }
    }

    return ransomMap.size === 0
};

console.log(canConstruct("aac", "aab"));